package com.lewis.module.m2.api.record.controller;

import com.lewis.common.core.entity.BaseResult;
import com.lewis.common.mongodb.MongodbUtil;
import com.lewis.module.m2.api.record.entity.ChatDetail;
import com.lewis.module.m2.api.record.entity.QqDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.bson.types.ObjectId;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * qq记录controller
 *
 * @author Lewis - 398529803@qq.com
 * @date 2022年5月17日, 017 - 15:47:21
 */
@Api(tags = "qq记录")
@RestController
@RequestMapping("/record/qq/detail")
public class RecordQqDetailController {

	@Resource
	private MongodbUtil mongodbUtil;

	@ApiOperation(value = "记录列表")
	@GetMapping("/list")
	public BaseResult list(QqDetail qqDetail) {
		return BaseResult.ok().setData(mongodbUtil.list(mongodbUtil.createQuery(), QqDetail.class));
	}

	@ApiOperation(value = "新增记录")
	@PostMapping("/add")
	public BaseResult add(@RequestBody QqDetail qqDetail) {
		qqDetail.setId(new ObjectId().toString());
		return BaseResult.ok().setData(mongodbUtil.save(qqDetail));
	}

	@ApiOperation(value = "获取记录详情")
	@GetMapping("/getById")
	public BaseResult getById(String id) {
		return BaseResult.ok().setData(mongodbUtil.getOneById(id, QqDetail.class));
	}

	@ApiOperation(value = "修改记录")
	@PostMapping("/update")
	public BaseResult update(@RequestBody ChatDetail chatDetail) {
		return BaseResult.ok().setData(mongodbUtil.save(chatDetail));
	}
}
